﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using Users;
using Lists;
using Sim;


namespace Lists
{
    static public class TournamentList
    {
        static public List<Tournament> tournamentList { get; set; }
        
        static TournamentList()
        {
            tournamentList = new List<Tournament>();
        }

        static public void AddTournament(Tournament t)
        {
            DeserializeFromXML();
            tournamentList.Add(t);
            SerializeToXML();
        }

        static public void RemoveTournament(int index)
        {
            tournamentList.RemoveAt(index);
        }

        static public void SerializeToXML()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<Tournament>), new XmlRootAttribute("TOURNEYS"));
            TextWriter textWriter = new StreamWriter("tourneys.xml");
            serializer.Serialize(textWriter, tournamentList);
            textWriter.Close();
        }

        static public void DeserializeFromXML()
        {
            tournamentList.Clear();
            XmlSerializer deserializer = new XmlSerializer(typeof(List<Tournament>), new XmlRootAttribute("TOURNEYS"));
            TextReader textReader = new StreamReader("tourneys.xml");
            tournamentList = (List<Tournament>)deserializer.Deserialize(textReader);
            textReader.Close();
        }
    }
}
